local Players = game:GetService("Players") local Lighting = game:GetService("Lighting") local RunService = game:GetService("RunService") local pCFrames = {} local owner: Player = owner local airTimes = {} local checks = { float = function(currentCFrame, oldCF, hrp, dt) local params = RaycastParams.new() params.FilterType = Enum.RaycastFilterType.Blacklist params.FilterDescendantsInstances = { hrp:FindFirstAncestorWhichIsA("Model") } if airTimes[hrp] and airTimes[hrp] > 5 then airTimes[hrp] = 0 local ray = workspace:Raycast(currentCFrame.Position, Vector3.fromNormalId(Enum.NormalId.Bottom).Unit * 100, params) if ray and currentCFrame.Y == oldCF.Y then hrp.Position = ray.Position print("tp back to ground scrub") airTimes[hrp] = 0 elseif not ray and currentCFrame.Y == oldCF.Y then airTimes[hrp] = 0 return true, "airTime > 2 && oldY = y" end end local ray = workspace:Raycast(currentCFrame.Position, Vector3.fromNormalId(Enum.NormalId.Bottom).Unit * 5, params) if not ray then airTimes[hrp] += dt else airTimes[hrp] = 0 end end, speed = function(currentCFrame, oldCFrame, hrp) local subtractedVector = (currentCFrame.Position - oldCFrame.Position) local xz = math.abs(subtractedVector.X) + math.abs(subtractedVector.Z) return xz > 2.8 + (owner:GetNetworkPing() * 5), "too fast" end, } local function lagback(humanoidRootPart: Part) task.spawn(function() pcall(function() local s = os.clock() humanoidRootPart:SetNetworkOwner() while task.wait() do humanoidRootPart.AssemblyAngularVelocity = Vector3.zero humanoidRootPart.CFrame = pCFrames[humanoidRootPart] or humanoidRootPart.CFrame if os.clock() - s >= 0.5 then break end end humanoidRootPart:SetNetworkOwner( Players:GetPlayerFromCharacter(humanoidRootPart:FindFirstAncestorWhichIsA("Model")) ) end) end) end local debug = true local function detect(humanoidRootPart: Part, dt) if not pCFrames[humanoidRootPart] then pCFrames[humanoidRootPart] = humanoidRootPart.CFrame end for checkName, func in pairs(checks) do local shouldLagback, reason = func(humanoidRootPart.CFrame, pCFrames[humanoidRootPart], humanoidRootPart, dt) if shouldLagback then if debug then print(string.format("failed %s. reason: %s", checkName, reason)) end lagback(humanoidRootPart) return end end pCFrames[humanoidRootPart] = humanoidRootPart.CFrame end RunService.Heartbeat:Connect(function(dt) Lighting:ClearAllChildren() for _, v in pairs(Players:GetPlayers()) do local hrp = v.Character and v.Character and v.Character:FindFirstChild("HumanoidRootPart") if hrp then pcall(function() detect(hrp, dt) end) end end end)